package com.talent.service.iot.websocket.handler;

import io.netty.channel.Channel;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName：UserChannelSession
 * @Author: hszhou
 * @Date: 2024/12/6 14:33
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class UserChannelSession {


    //业务ID与通道的关系映射
    private static Map<String, Channel> session = new HashMap<>();

    //客户端的长ID与业务ID的关系映射
    private static Map<String,String> deviceIdRelation = new HashMap<>();

    //客户端有一个长ID 是系统生成的  跟这个与客户端的唯一标识 如userId，deviceId相关联 后面能够找到是哪一个channel
    public static void  putDeviceIdRelation(String channelId,String deviceId){
        deviceIdRelation.put(channelId,deviceId);
    }

    public static String  getDeviceIdRelation(String channelId){
       return deviceIdRelation.get(channelId);
    }

    public static void  putSession(String deviceId,Channel channel){
        session.put(deviceId,channel);
    }

    public static Channel  getSession(String deviceId){
       return session.get(deviceId);
    }

    public void removeUselessChannels(String deviceId){
        session.remove(deviceId);
    }

}
